package com.atguigu.ggkt.vod.controller;

import com.atguigu.ggkt.result.Result;
import com.atguigu.ggkt.vod.service.FileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@Api(tags = "文件上传接口")
@RestController
@RequestMapping("/admin/vod/file")
//@CrossOrigin
public class FileUploadController {
    @Resource
    private FileService fileService;

    @ApiOperation("文件上传")
    @PostMapping(value = "upload",consumes = "multipart/form-data")
    public Result uploadFile(@ApiParam(name = "file", value = "文件", required = true)
                                 @RequestPart("file") //表示上传的是文件，如果不标注为RequestPart会被swagger默认为普通的json对象请求
                                 MultipartFile file){
        String url = fileService.upload(file);
        return Result.ok(url).message("文件上传成功！");
    }

}
